from pydantic import BaseModel, Field
from typing import Literal, Optional, List
from datetime import date, datetime


# 试卷信息模型
# class PaperSchema(BaseModel):
#     paper_id: int
#     course_id: int
#     paper_name: str = Field(..., max_length=50)
#     total_score: int = Field(ge=0, le=100)
#     exam_time: int = Field(ge=30, le=180, description="考试时长(分钟)")
#     difficulty: Literal["简单", "中等", "困难"] = "中等"
#     create_date: date
#     creator_id: int
#     semester: str = Field(..., max_length=20)
#     is_used: bool = True
#
#     class Config:
#         from_attributes = True

class PaperBase(BaseModel):
    title: str = Field(..., max_length=255, description="试卷名称")
    choice_count: Optional[int] = Field(0, ge=0, description="选择题数量")
    fill_count: Optional[int] = Field(0, ge=0, description="填空题数量")
    short_count: Optional[int] = Field(0, ge=0, description="简答题数量")
    difficulty_range: Optional[int] = Field(5, ge=1, le=10, description="难度范围（1-10）")
    major: str = Field(..., max_length=100, description="所属专业")
    course: str = Field(..., max_length=100, description="课程名称")
    subject_requirements: Optional[str] = Field(None, description="考的啥主题")
    question_ids: List[int] = Field(..., description="包含的题目ID列表")
    total_score: Optional[int] = Field(100, ge=0, description="试卷总分")
    time_limit: Optional[int] = Field(120, ge=0, description="考试时长（分钟）")

class PaperCreate(PaperBase):
    """创建试卷时使用的模型"""
    pass

class PaperUpdate(BaseModel):
    """更新试卷时使用的模型（字段均为可选）"""
    title: Optional[str] = Field(None, max_length=255, description="试卷名称")
    choice_count: Optional[int] = Field(None, ge=0, description="选择题数量")
    fill_count: Optional[int] = Field(None, ge=0, description="填空题数量")
    short_count: Optional[int] = Field(None, ge=0, description="简答题数量")
    difficulty_range: Optional[int] = Field(None, ge=1, le=10, description="难度范围（1-10）")
    major: Optional[str] = Field(None, max_length=100, description="所属专业")
    course: Optional[str] = Field(None, max_length=100, description="课程名称")
    subject_requirements: Optional[str] = Field(None, description="考的啥主题")
    question_ids: Optional[List[int]] = Field(None, description="包含的题目ID列表")
    total_score: Optional[int] = Field(None, ge=0, description="试卷总分")
    time_limit: Optional[int] = Field(None, ge=0, description="考试时长（分钟）")

class PaperOut(PaperBase):
    """查询试卷时返回的模型（包含主键和创建时间）"""
    id: int
    created_at: datetime

    class Config:
        from_attributes = True # 支持从ORM模型转换